package com.jiuyun.servlet;

import com.jiuyun.dao.StudentaDao;
import com.jiuyun.dao.impi.StudentaDaoimpl;
import com.jiuyun.entity.Teachar;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/teacher/*")
public class TeacherServlet extends BaseServlet {
    StudentaDao dao=new StudentaDaoimpl();

    protected void find(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List list=null;
        try {
            list=dao.laoshuAll();
            System.out.println(list);
            request.getSession().setAttribute("list",list);
        } catch (SQLException throwables){
            throwables.printStackTrace();
        }
        response.sendRedirect("/Eventstar/houtai/laoshu.jsp");
    }


    protected void add(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("老师添加");
        String name=request.getParameter("name");
        String pass=request.getParameter("pass");
        String dh=request.getParameter("dh");
        String zw=request.getParameter("zw");
        Teachar tea=new Teachar(name,pass,dh,zw);
        int a=0;
        try {
            a=dao.laoshuadd(tea);
            System.out.println(a);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        response.sendRedirect("teacher/find");
    }
    protected void del(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int teaid=Integer.parseInt(request.getParameter("teaid"));
        try {
            dao.laoshudel(teaid);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        response.sendRedirect("teacher/find");
    }
    protected void update(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("老师修改");
        String name=request.getParameter("name");
        String pass=request.getParameter("pass");
        String dh=request.getParameter("dh");
        String zw=request.getParameter("zw");
        int id=Integer.parseInt(request.getParameter("id"));
        try {
            dao.updatelaoshu(name,pass,dh,zw,id);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        response.sendRedirect("teacher/find");
    }
    protected void xiugai(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
        int teaid=Integer.parseInt(request.getParameter("gid"));
        System.out.println(teaid);
        List<Teachar> list=dao.laoshutjAll(teaid);
        System.out.println(list);
        HttpSession session=request.getSession();
        session.setAttribute("laoshilist",list);
        response.sendRedirect("/Eventstar/houtai/laoshixiugai.jsp");
    }
}
